<template>
  <div>
    <div>
      <div class="wy-filter">
        <el-input placeholder="请输入要搜索的检查编码" v-model="query.techCode"></el-input>
        <el-input placeholder="请输入要搜索的检查名称" v-model="query.techName"></el-input>
        <el-button type="primary" @click="search">搜索</el-button>
        <el-button type="primary" @click="add">添加</el-button>
      </div>
      <el-table ref="wytable" :data="tableData">
        <el-table-column type="selection" width="55" />
        <el-table-column show-overflow-tooltip label="检查编码" prop="techCode"></el-table-column>
        <el-table-column show-overflow-tooltip label="检查名称" prop="techName"></el-table-column>
        <el-table-column label="检查规格" prop="techFormat"></el-table-column>
        <el-table-column label="单价" prop="techPrice"></el-table-column>
        <el-table-column label="费用分类" prop="priceType"></el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script setup>
import { reactive, ref } from 'vue'
import { get } from '@/util/axios'
import { ElMessage } from 'element-plus'
const wytable = ref()
const props = defineProps(['checktype'])
const emits = defineEmits(['update:tableData'],['update:show'])
const query = reactive({
  techCode: '',
  techName: ''
})
const tableData = ref([])
function search () {
  if (query.techCode.trim() || query.techName.trim()) {
    getTableData()
  } else {
    ElMessage.error('至少要输入一个条件')
  }
}
function getTableData () {
  get('/medicalTechnology/list', {...query, type: props.checktype }, content => {
    tableData.value = content
  })
}
function add () {
  const rows = wytable.value.getSelectionRows()
  if (rows.length !== 1) {
    ElMessage.error('必须选择,且只能选择一个检查项目')
  } else {
    emits('update:tableData', rows)
    emits('update:show',false)
  }
}
</script>

<style scoped lang="scss">
</style>
